#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using WaveMaster.Holidays.Club.Service;
using System.Configuration;
using System.Collections;
using ThoughtWorks.QRCode.Codec;
using System.IO;
using WaveMaster.Holidays.Club.Domain;

#endregion

namespace WaveMaster.Holidays.Club.Web
{
    public partial class PrintWildCardForm : Form
    {
        CheckInService m_BookingService;

        public PrintWildCardForm(long id, User m_currentUser)
        {
            InitializeComponent();
            this.Text = "Print Wild Card";

            m_BookingService = new CheckInService();// (CheckInService)ServiceFactory.Instance().GetService(ServiceFactory.BOOKING_SERVICE);

            DataSet result = m_BookingService.ReportItineraryBookingPassengerByID(id);
            //result.Tables[0].Columns.Add("barcodeImage", typeof(byte[]));
            //ArrayList l = new ArrayList();
            //int i = result.Tables[0].Rows[0].ItemArray.Length;
            //int j = 0;
            //foreach (object o in result.Tables[0].Rows[0].ItemArray)
            //{
            //    if (j == (i - 1))
            //    {
            //        l.Add(getBarcode2DImage(l[23].ToString()));// index 23 is boarding pass code.
            //    }
            //    else
            //        l.Add(o);
            //    j++;
            //}
            //result.Tables[0].Rows[0].ItemArray = l.ToArray();
            //result.WriteXml(@"D:\My Projects\WaveMasterBoardingManagementSystem\ReportBoardingPass.xml", XmlWriteMode.WriteSchema);

            result.WriteXml(ConfigurationManager.AppSettings["ReportDataTemp"] + "ReportWildCard" + m_currentUser.UserID + ".xml", XmlWriteMode.WriteSchema);
            htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?ReportDataSource=ReportWildCard" + m_currentUser.UserID + ".xml&ReportFile=ReportWildCard.rpt";
            htmlBox1.Update();


            //string reportID = ServiceFactory.GenerateRandomID().ToString();
            //Session["ReportBoardingPassData" + reportID] = result;
            //Session["ReportBoardingPassFile" + reportID] = "ReportWildCard.rpt";
            //string param1 = "ReportDataSource=ReportBoardingPassData" + reportID;
            //string param2 = "ReportFile=ReportBoardingPassFile" + reportID;
            //htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?" + param1 + "&" + param2;
            ////htmlBox1.Url = "http://" + this.Context.HttpContext.Request.ServerVariables["SERVER_NAME"] + ":" + this.Context.HttpContext.Request.ServerVariables["SERVER_PORT"] + @"/Report/" + "ReportViewer.aspx?" + param1 + "&" + param2;
            //htmlBox1.Update();
        }

        public byte[] getBarcode2DImage(string text)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            qrCodeEncoder.QRCodeScale = 4;
            qrCodeEncoder.QRCodeVersion = 7;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            Image image = qrCodeEncoder.Encode(text);
            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            return ms.ToArray();
        }
    }
}